package net.dgitc.xingyannian.mapper;

import net.dgitc.xingyannian.entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * StudentMapper
 *
 * @author XING&WANG
 * @version 2024/08/26 19:41
 **/
@Mapper
public interface StudentMapper {
    // 插入学生信息
    @Insert("INSERT INTO student (sId, sName, sPid, sClass, sRoomInfo, sTeacher) VALUES (#{sId}, #{sName}, #{sPid}, #{sClass}, #{sRoomInfo}, #{sTeacher})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insertStudent(Student student);

    // 根据ID查询学生信息
    @Select("SELECT * FROM student WHERE id = #{id}")
    Student getStudentById(@Param("id") Integer id);

    // 查询所有学生信息
    @Select("SELECT * FROM student")
    List<Student> getAllStudents();

    // 根据学号查询学生信息
    @Select("SELECT * FROM student WHERE sId = #{sId}")
    Student getStudentBySId(@Param("sId") String sId);

    // 更新学生信息
    @Update("UPDATE student SET sId=#{sId}, sName=#{sName}, sPid=#{sPid}, sClass=#{sClass}, sRoomInfo=#{sRoomInfo}, sTeacher=#{sTeacher} WHERE id=#{id}")
    int updateStudent(Student student);

    // 删除学生信息
    @Delete("DELETE FROM student WHERE id = #{id}")
    int deleteStudent(@Param("id") Integer id);
    // 根据姓名、身份证号查询学生信息
    @Select("SELECT * FROM student WHERE sName = #{sName} AND sPid = #{sPid}")
    Student getStudentByNameAndPid(@Param("sName") String sName, @Param("sPid") String sPid);
}
